package o;

import android.app.ActivityOptions;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.widget.ImageView;
import androidx.annotation.RequiresApi;
import com.huawei.android.app.ActivityManagerEx;
import com.huawei.android.content.ContextEx;
import com.huawei.android.os.UserHandleEx;
import com.huawei.appgallery.assistantdock.gamemode.card.BuoyBaseEnterCard;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import o.beo.f;
import o.biu.a;

public class bhs extends BuoyBaseEnterCard {
    private boolean ʻ;
    private String ʽ;
    private String ˊॱ;
    private ImageView ˏॱ;
    private String ᐝ;

    public bhs(Context context, String str, boolean z) {
        super(context);
        this.ʽ = str;
        this.ʻ = z;
    }

    public bhs(Context context, a aVar) {
        super(context);
        if (aVar == null) {
            Logger.e("FreeFormEnterCardBuoy", "create FreeFormEnterCardBuoy fail,appInfo == null");
            return;
        }
        String ˊ = aVar.ˊ();
        if (ˊ.startsWith("free_form_clone|")) {
            this.ʽ = ˊ.replace("free_form_clone|", "");
            this.ʻ = true;
        } else if (ˊ.startsWith("free_form|")) {
            this.ʽ = ˊ.replace("free_form|", "");
            this.ʻ = false;
        } else {
            Logger.e("FreeFormEnterCardBuoy", "create FreeFormEnterCardBuoy fail,appInfo's key is invalid");
            return;
        }
        this.ᐝ = aVar.ˏ();
        this.ˊॱ = aVar.ˎ();
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        this.ˏॱ = (ImageView) ˉ().findViewById(beo$e.ʼˊ);
        if (big.ˎ(this.ʽ)) {
            this.ˏॱ.setVisibility(8);
            try {
                PackageManager packageManager = this.ʼॱ.getPackageManager();
                ApplicationInfo applicationInfo = this.ʼॱ.getPackageManager().getApplicationInfo(this.ʽ, DnsConfig.MAX_CACHE_ENTRIES);
                this.ˊ.setText(applicationInfo.loadLabel(packageManager));
                if (this.ʻ) {
                    bhp ˏ = big.ˏ(this.ʽ, true);
                    Drawable loadIcon = applicationInfo.loadIcon(packageManager);
                    if (ˏ == null) {
                        Logger.e("FreeFormEnterCardBuoy", "freeFormAppStartInfo == null");
                    } else if (VERSION.SDK_INT >= 21) {
                        loadIcon = packageManager.getUserBadgedIcon(loadIcon, UserHandleEx.getUserHandle(ˏ.ˏ().getUserInfoId()));
                    }
                    this.ʼ.setBackground(loadIcon);
                    return;
                }
                this.ʼ.setBackground(applicationInfo.loadIcon(packageManager));
                return;
            } catch (Exception e) {
                Logger.e("FreeFormEnterCardBuoy", "setData error");
                return;
            }
        }
        Logger.ˎ("FreeFormEnterCardBuoy", "packageName is not install , load online info");
        this.ˊ.setText(this.ˊॱ);
        eqx.ˏ(this.ʼ, this.ᐝ, "app_default_icon");
        this.ʼ.setImageAlpha(DnsConfig.MAX_CACHE_ENTRIES);
        this.ˏॱ.setVisibility(0);
    }

    private int ˏॱ() {
        try {
            if (!bii.ʼ()) {
                return 5;
            }
            Logger.ˎ("FreeFormEnterCardBuoy", "support HwMultiWindow");
            return 102;
        } catch (Throwable th) {
            Logger.e("FreeFormEnterCardBuoy", "getWindowModeType Exception");
            return 5;
        }
    }

    @RequiresApi(api = 23)
    public void ˋ() {
        if (this.ʻ && !big.ˊ(this.ʽ)) {
            ezn.ˊ().ˊ(this.ʼॱ.getResources().getString(f.ͺ));
        } else if (big.ˏ(this.ʽ)) {
            Logger.ˎ("FreeFormEnterCardBuoy", "shouldSkipFreeForm for:" + this.ʽ);
            ezn.ˊ().ˊ(this.ʼॱ.getResources().getString(f.ˋॱ));
        } else if (big.ˎ(this.ʽ)) {
            ˊॱ();
        } else {
            ॱˊ();
        }
    }

    @RequiresApi(api = 23)
    private void ˊॱ() {
        fam.ॱ().ˏ(this.ʼॱ);
        ˏ("CLICK");
        int ˏॱ = ˏॱ();
        if (big.ˊ(this.ʽ)) {
            bhp ˏ = big.ˏ(this.ʽ, this.ʻ);
            if (ˏ == null || ˏ.ˏ() == null) {
                Logger.e("FreeFormEnterCardBuoy", "getAppInfo == null || getUserInfoEx() == null");
                return;
            }
            Intent ˋ = ˏ.ˋ();
            if (ˋ == null) {
                Logger.e("FreeFormEnterCardBuoy", "intent == null");
                return;
            }
            try {
                Method declaredMethod = ˋ.getClass().getDeclaredMethod("addHwFlags", new Class[]{Integer.TYPE});
                Field declaredField = ˋ.getClass().getDeclaredField("FLAG_HW_ACTIVITY_FOR_DUAL_CHOOSER");
                declaredField.setAccessible(true);
                if (declaredField.get(null) instanceof Integer) {
                    declaredMethod.invoke(ˋ, new Object[]{(Integer) declaredField.get(null)});
                } else {
                    Logger.e("FreeFormEnterCardBuoy", "flag is not Integer");
                }
            } catch (Throwable th) {
                Logger.e("FreeFormEnterCardBuoy", "NoSuchMethodException");
            }
            ActivityOptions makeBasic = ActivityOptions.makeBasic();
            ActivityManagerEx.setLaunchWindowingMode(makeBasic, ˏॱ, this.ʼॱ);
            ˋ.addFlags(268435456);
            ContextEx.startActivityAsUser(this.ʼॱ, ˋ, makeBasic.toBundle(), UserHandleEx.getUserHandle(ˏ.ˏ().getUserInfoId()));
            return;
        }
        Intent launchIntentForPackage = this.ʼॱ.getPackageManager().getLaunchIntentForPackage(this.ʽ);
        if (launchIntentForPackage == null) {
            Logger.e("FreeFormEnterCardBuoy", "intent == null");
            return;
        }
        ActivityOptions makeBasic2 = ActivityOptions.makeBasic();
        ActivityManagerEx.setLaunchWindowingMode(makeBasic2, ˏॱ, this.ʼॱ);
        launchIntentForPackage.addFlags(268435456);
        this.ʼॱ.startActivity(launchIntentForPackage, makeBasic2.toBundle());
    }

    private void ॱˊ() {
        Intent intent = new Intent();
        intent.setAction("com.huawei.appmarket.intent.action.AppDetail");
        intent.putExtra("APP_PACKAGENAME", this.ʽ);
        intent.setPackage("com.huawei.appmarket");
        intent.addFlags(268435456);
        try {
            fam.ॱ().ˊ(this.ʼॱ, null, intent);
        } catch (ActivityNotFoundException e) {
            Logger.e("openAppDetail fail", "openAppDetail activity not found");
        }
    }

    public String ᐝ() {
        return "free_form|" + this.ʽ;
    }
}
